1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.webmacro.engine;
25
26 import org.webmacro.Context;
27 import org.webmacro.Macro;
28 import org.webmacro.PropertyException;
29
30
31 /***
32 * Operate on bean properties of an existing macro; used when a Macro
33 * is passed as an argument to a macro
34 * @author Brian Goetz
35 * @since 1.1
36 */
37 public class MacroPropertyVariable extends Variable
38 {
39
40 private Macro value;
41
42 /***
43 * No special initialization
44 */
45 MacroPropertyVariable (Macro value, Object names[])
46 {
47 super(names);
48 this.value = value;
49 }
50
51 /***
52 * Look up my value in the corresponding Map, possibly using introspection,
53 * and return it
54 * @exception PropertyException If the property does not exist
55 */
56 public final Object getValue (Context context)
57 throws PropertyException
58 {
59 Object v = value.evaluate(context);
60 if (v == null)
61 throw new PropertyException.NullValueException(_names[0].toString());
62 else
63 return context.getBroker()
64 ._propertyOperators.getProperty(context, v, _names, 1);
65 }
66
67 /***
68 * Look up my the value of this variable in the specified Map, possibly
69 * using introspection, and set it to the supplied value.
70 * @exception PropertyException If the property does not exist
71 */
72 public final void setValue (Context context, Object newValue)
73 throws PropertyException
74 {
75 throw new PropertyException("Cannot set properties of a constant");
76 }
77
78 /***
79 * Return a string representation naming the variable for
80 * debugging purposes.
81 */
82 public final String toString ()
83 {
84 return "macro-property:" + getVariableName();
85 }
86
87 }